<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix">
        <span>发布通知</span>
      </div>
      <div>
        <el-input v-model="pool" type="text" />
        <el-button @click.prevent="getData">导出文件</el-button>
        <!-- <div>{{ out }}</div> -->
      </div>
    </el-card>

  </div>
</template>

<script>
import { timeList } from '@/api/admin'
import FileSaver from 'file-saver'
export default {
  data() {
    return {
      pool: '',
      json: '',
      out: []
    }
  },
  methods: {
    getData() {
      timeList({ 'pool': this.pool }).then(data => {
        this.out = []
        for (const item of data.data.data) {
          // console.log(item)
          const tmp = this.checkOut(item.name)
          if (tmp === 'yes') {
            // console.log()
            this.out.push({ name: item.name, img: 'https://cdn.staticaly.com/gh/maicent/pic@master/arknights/头像_' + item.name + '.webp', [item.time]: item.num })
          } else {
            this.out[tmp][item.time] = item.num
          }
        }
        const dataout = JSON.stringify(this.out)
        const blob = new Blob([dataout], { type: '' })
        FileSaver.saveAs(blob, 'ark.json')
      })
    },
    checkOut(name) {
      for (const i in this.out) {
        if (this.out[i].name === name) {
          return i
        }
      }
      return 'yes'
    }
  }
}
</script>

<style scoped>
.release-item{
  margin: 10px 0px 10px 10px;
  float: right;
}
.demo-dynamic{
  display: flex;
  width: 460px;
  padding-bottom: 10px;
  margin-right:10px;
  vertical-align:top
}

.demo-dynamic .el-button{
  margin-block: auto;
  margin-left: 10px;
}

</style>

